home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 June / PCWorld_2007-06_cd.bin / v cisle / tclock / tclocklight-040702-3.exe / source / dll / main2.c < prev    next >
C/C++ Source or Header  |  2004-02-13  |  4KB  |  153 lines

  1. /*-------------------------------------------------------------
  2.   main2.c : initialize and clear up
  3.   (C) 1997-2003 Kazuto Sato
  4.   Please read readme.txt about the license.
  5.   
  6.   Written by Kazubon, Nanashi-san
  7. ---------------------------------------------------------------*/
  8.  
  9. #include "tcdll.h"
  10.  
  11. /* Globals */
  12.  
  13. void InitClock(HWND hwnd);
  14. void EndClock(HWND hwnd);
  15. void OnDestroy(HWND hwnd);
  16. void LoadSetting(HWND hwnd);
  17.  
  18. BOOL    g_bInitClock = FALSE;  // InitTClock() has been called
  19. HANDLE  g_hInst;               // instanse handle
  20. WNDPROC g_oldWndProc;          // clock's window procedure
  21. BOOL    g_bIniSetting;         // use tclock.ini
  22. char    g_inifile[MAX_PATH];   // ini file name
  23. char    g_mydir[MAX_PATH];     // path of tcdll.dll
  24. int     g_winver;              // Windows version
  25. BOOL    g_bIE4;                // IE 4 or later
  26. BOOL    g_bVisualStyle;        // Windows XP theme is used
  27. BOOL    g_bNoClock;            // don't customize clock
  28.  
  29.  
  30. /*------------------------------------------------
  31.   initialize the clock
  32. --------------------------------------------------*/
  33. void InitClock(HWND hwnd)
  34. {
  35.     if(g_bInitClock) return;
  36.     g_bInitClock = TRUE;
  37.     
  38.     g_hInst = GetModuleHandle(DLLFILENAME);
  39.     
  40.     g_winver = CheckWinVersion();       // common/util.c
  41.     g_bIE4 = IsIE4();                   // common/util.c
  42.     g_bVisualStyle = IsXPVisualStyle(); // common/util.c
  43.     
  44.     // check subclassification
  45.     if(IsSubclassed(hwnd))
  46.     {
  47.         SendMessage(g_hwndTClockMain, TCM_CLOCKERROR, 0, 6);
  48.         return;
  49.     }
  50.     
  51.     GetModuleFileName(g_hInst, g_mydir, MAX_PATH);
  52.     del_title(g_mydir);
  53.     
  54.     strcpy(g_inifile, g_mydir);
  55.     add_title(g_inifile, "tclock.ini");
  56.     g_bIniSetting = TRUE;
  57. /*  g_bIniSetting = FALSE;
  58.     if(IsFile(g_inifile)) g_bIniSetting = TRUE; */
  59.     
  60.     // tell tclock.exe clock's HWND
  61.     PostMessage(g_hwndTClockMain, TCM_HWNDCLOCK, 0, (LPARAM)hwnd);
  62.     
  63.     // read settings
  64.     LoadSetting(hwnd);
  65.     
  66.     InitTooltip(hwnd); // tooltip.c
  67.     InitUserStr();     // userstr.c
  68.     
  69.     // subclassfy the clock window !!
  70.     g_oldWndProc = (WNDPROC)GetWindowLong(hwnd, GWL_WNDPROC);
  71.     SetWindowLong(hwnd, GWL_WNDPROC, (LONG)WndProc);
  72.     
  73.     // don't accept double clicks
  74.     SetClassLong(hwnd, GCL_STYLE,
  75.         GetClassLong(hwnd, GCL_STYLE) & ~CS_DBLCLKS);
  76.     
  77.     InitStartButton(hwnd);  // startbtn.c
  78.     InitStartMenu(hwnd);   // startmenu.c
  79.     InitTaskbar(hwnd);      // taskbar.c
  80.     InitTaskSwitch(hwnd);  // taskswitch.c
  81.     InitTrayNotify(hwnd);  // traynotify.c
  82.     
  83.     RefreshTaskbar(hwnd);  // taskbar.c
  84.     
  85.     SetTimer(hwnd, IDTIMER_MAIN, 1000, NULL);
  86.     
  87. }
  88.  
  89. /*------------------------------------------------
  90.   ending process
  91. --------------------------------------------------*/
  92. void EndClock(HWND hwnd)
  93. {
  94.     static BOOL bEndClock = FALSE;
  95.     
  96.     if(bEndClock) return; // avoid to be called twice
  97.     bEndClock = TRUE;
  98.     
  99.     g_bVisualStyle = IsXPVisualStyle();
  100.     
  101.     DragAcceptFiles(hwnd, FALSE);
  102.     
  103.     EndTrayNotify();    // traynotify.c
  104.     EndTaskSwitch();    // taskswitch.c
  105.     EndTaskbar(hwnd);   // taskbar.c
  106.     EndStartMenu();     // startmenu.c
  107.     EndStartButton();   // startbtn.c
  108.     ClearDrawing();     // drawing.c
  109.     EndTooltip(hwnd);   // tooltip.c
  110.     
  111.     EndNewAPI();      // newapi.c
  112.     
  113.     // Stop timers
  114.     KillTimer(hwnd, IDTIMER_MAIN);
  115.     
  116.     // restore window procedure
  117.     SetWindowLong(hwnd, GWL_WNDPROC, (LONG)g_oldWndProc);
  118.     g_oldWndProc = NULL;
  119.     
  120.     RefreshTaskbar(hwnd);  // taskbar.c
  121.     
  122.     // close window of tclock.exe
  123.     PostMessage(g_hwndTClockMain, WM_CLOSE, 0, 0);
  124.     
  125.     PostMessage(hwnd, WM_TIMER, 0, 0);
  126. }
  127.  
  128. /*-------------------------------------------------------------
  129.   WM_DESTROY message
  130. ---------------------------------------------------------------*/
  131. void OnDestroy(HWND hwnd)
  132. {
  133.     ClearStartMenuResource();   // startmenu.c
  134.     ClearStartButtonResource(); // startbtn.c
  135.     ClearDrawing();             // drawing.c
  136. }
  137.  
  138. /*-------------------------------------------------------------
  139.    read settings and initialize
  140.    this function is called in InitClock() and OnRefreshClock()
  141.    ReadData() in old version
  142. ---------------------------------------------------------------*/
  143. void LoadSetting(HWND hwnd)
  144. {
  145.     g_bNoClock = GetMyRegLong(NULL, "NoClock", FALSE);
  146.     
  147.     DragAcceptFiles(hwnd, GetMyRegLong(NULL, "DropFiles", FALSE));
  148.     
  149.     LoadFormatSetting(hwnd);   // format.c
  150.     LoadDrawingSetting(hwnd);  // drawing.c
  151. }
  152.  
  153.